<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://brs_web.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="referrer" content="no-referrer" />

    <title>Book Store</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>

<body>
    <div id="wrap">

        <div class="header">
            <div class="logo">
                <a href="index.html"><img src="images/logo.gif" alt="" title="" border="0" /></a>
            </div>
            <div id="menu">
                <ul>
                    <li><a href="index.html">首页</a></li>
                    <li><a href="category.html">全部书籍</a></li>
                    <li><a href="specials.html">推荐书籍</a></li>

                </ul>
            </div>


        </div>


        <div class="center_content">
            <div class="left_content">
                <!-- <div id="left1"> -->
                <div class="title"><span class="title_icon"><img src="images/bullet1.gif" alt="" title=""/></span>我的账户
                </div>

                <div class="feat_prod_box_details">
                    <!--<p class="details">
                 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud.
                </p>-->

                    <div class="contact_form">
                        <div class="form_subtitle">登陆你的账户</div>
                        <form name="register">
                            <div class="form_row">
                                <label class="contact"><strong>用户名:</strong></label>
                                <input type="text" class="contact_input" id="username" />
                            </div>


                            <div class="form_row">
                                <label class="contact"><strong>密码:</strong></label>
                                <input type="text" class="contact_input" id="password" />
                            </div>


                            <div class="form_row">
                                <input type="submit" class="register" value="登陆" id="login" />
                            </div>
                            <p class="msg"></p>
                        </form>

                    </div>

                </div>


                <div class="clear"></div>
            </div>
            <!--end of left content-->

            <div class="right_content">
                <!-- <div id="right1"> -->

                <!--<div class="languages_box">
            <span class="red">Languages:</span>
            <a href="#"><img src="images/gb.gif" alt="" title="" border="0" /></a>
            <a href="#"><img src="images/fr.gif" alt="" title="" border="0" /></a>
            <a href="#"><img src="images/de.gif" alt="" title="" border="0" /></a>
            </div>
                <div class="currency">
                <span class="red">Currency: </span>
                <a href="#">GBP</a>
                <a href="#">EUR</a>
                <a href="#"><strong>USD</strong></a>
                </div>-->


                <div class="cart">
                    <div class="home_cart_content">
                        <span id="userName1" style="font-size: 20px; margin-right: 20px;" hidden="hidden">你好游客</span> <span class="red"><a href="register.html">注册</a></span>
                        <span class="red" style="margin-left: 20px"><a href="myaccount.html">登陆</a></span>
                    </div>

                </div>

                <div class="title"><span class="title_icon"><img src="images/bullet3.gif" alt="" title=""/></span>关于我们
                </div>
                <div class="about">
                    <p>
                        <img src="images/about.gif" alt="" title="" class="right" /> 歌德曾经说过：“读一本好书,就是和一位品德高尚的人谈话.”是的,读好书,就像结交了良师益友,使我们获益匪浅；读好书,就像沐浴在温暖的春风里,使我们心旷神怡；读好书,就像找到了快乐的源泉,使我们领悟到快乐的真谛!
                    </p>

                </div>

                <div class="right_box">

                    <div class="title"><span class="title_icon"><img src="images/bullet4.gif" alt="" title=""/></span>随便看看
                    </div>
                    <div class="new_prod_box">
                        <a href="details.html">product name</a>
                        <div class="new_prod_bg">
                            <span class="new_icon"><img src="images/promo_icon.gif" alt="" title=""/></span>
                            <a href="details.html"><img src="images/thumb1.gif" alt="" title="" class="thumb" border="0" /></a>
                        </div>
                    </div>

                    <div class="new_prod_box">
                        <a href="details.html">product name</a>
                        <div class="new_prod_bg">
                            <span class="new_icon"><img src="images/promo_icon.gif" alt="" title=""/></span>
                            <a href="details.html"><img src="images/thumb2.gif" alt="" title="" class="thumb" border="0" /></a>
                        </div>
                    </div>

                    <div class="new_prod_box">
                        <a href="details.html">product name</a>
                        <div class="new_prod_bg">
                            <span class="new_icon"><img src="images/promo_icon.gif" alt="" title=""/></span>
                            <a href="details.html"><img src="images/thumb3.gif" alt="" title="" class="thumb" border="0" /></a>
                        </div>
                    </div>

                </div>


            </div>
            <!--end of right content-->


            <div class="clear"></div>
        </div>
        <!--end of center content-->


        <div class="footer">
            <div class="left_footer"><img src="images/footer_logo.gif" alt="" title="" /><br/></div>

        </div>


    </div>

</body>
<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
<script src="./js/jquery.cookie.js"></script>

<!--<script type="text/javascript" src="./js/jquery.min.js"></script>-->
<script>
    function getCookie(name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return unescape(arr[2]);
        else
            return null;
    }

    function setCookie(name, value) {
        var Days = 30;
        var exp = new Date();
        // 30天过期
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
        document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
    }

    $(document).ready(function() {
        $('#login').click(function() {
            var name = document.getElementById('username').value;
            var pw = document.getElementById('password').value;
            var param = {
                "name": name
            };
            var bool = false;
            $.ajax({
                url: 'users/userLogin',
                type: "get",
                data: param,
                async: true,
                success: function(data) {
                    // alert(JSON.stringify(data));
                    if (data.length != 0) {
                        if (data[0].user_passwd == pw) {
                            bool = true;
                            $(".msg").css("color", "red");
                            $(".msg").text("登录成功！");
                            // 设置cookie
                            setCookie("username", name);
                            console.log(data[0].user_id);
                            setCookie("userId", data[0].user_id);
                            // 打印cookie
                            console.log(getCookie("username"));
                            window.location.href="index.html";
                        } else {
                            $(".msg").css("color", "red");
                            $(".msg").text("密码有误！");
                        }
                    } else {
                        $(".msg").css("color", "red");
                        $(".msg").text("用户名有误！");
                    }

                }
            });
            return bool;
        });
    });


</script>

</html>